import { initChanganInfo } from "./changan-info-util";
import {
  disableIOSBounce,
  getDevice,
  hideFloatButton,
  hideNavBar,
} from "@/cordova/common";
import { getDeviceInfo, setDeviceInfo } from "./common-storage";
import { Notify } from "vant";
import { WARNING_NOTIFY_STYLE_CONFIG } from "@/config/settings";
import { mockDeviceInfo } from "@/config/env-config";

const config = process.env.CONFIG as any;

async function initTokenAndEmployeeNo() {
  console.log("init token");
  await initChanganInfo().catch(() =>
    Notify({ message: "长安认证失败", ...WARNING_NOTIFY_STYLE_CONFIG })
  );
  // await getRawAppcubeToken().catch(() =>
  //   Notify({ message: "平台认证失败", ...WARNING_NOTIFY_STYLE_CONFIG })
  // );
}

async function initCordovaConfig() {
  hideFloatButton();
  disableIOSBounce();
  hideNavBar();

  if (!getDeviceInfo()) {
    let deviceInfo = await getDevice();
    if (!deviceInfo && config.env === "local") {
      deviceInfo = mockDeviceInfo;
    }
    console.log("----deviceInfo----", deviceInfo);
    setDeviceInfo(deviceInfo);
  }
}

export { initTokenAndEmployeeNo, initCordovaConfig };
